package com.simp.app.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ProgressBar;

import com.antonioleiva.mvpexample.app.R;
import com.simp.app.base.BaseActivity;
import com.simp.app.presenter.LoginPresenter;
import com.simp.app.presenter.impl.LoginPresenterImpl;
import com.simp.app.view.LoginView;

/**
 * 
 * Created by hanWG on 2015-10-21 下午4:24:44 $
 * 
 * @Description 登录界面
 *              <p/>
 */
public class LoginActivity extends BaseActivity implements LoginView,
		View.OnClickListener {
	private ProgressBar progressBar;
	private EditText username;
	private EditText password;
	private LoginPresenter presenter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_login);
		progressBar = (ProgressBar) findViewById(R.id.progress);
		username = (EditText) findViewById(R.id.username);
		password = (EditText) findViewById(R.id.password);
		findViewById(R.id.button).setOnClickListener(this);
		findViewById(R.id.button1).setOnClickListener(this);
		presenter = new LoginPresenterImpl(this);
	}

	@Override
	public void showProgress() {
		progressBar.setVisibility(View.VISIBLE);
	}

	@Override
	public void hideProgress() {
		progressBar.setVisibility(View.GONE);
	}

	@Override
	public void setUsernameError() {
		username.setError(getString(R.string.username_error));
	}

	@Override
	public void setPasswordError() {
		password.setError(getString(R.string.password_error));
	}

	@Override
	public void navigateToHome() {
		startActivity(new Intent(this, MainActivity.class));
		finish();
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.button1:
             showActivity(RegisterActivity.class);
			break;
		case R.id.button:
			presenter.validateCredentials(username.getText().toString(), password
					.getText().toString());
			break;
		default:
			break;
		}

	
	}
}
